﻿using FunArts.EasyDevOps.Shared.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace FunArts.EasyDevOps.Shared.Models.SshClient.Command
{
    /// <summary>
    /// 防火墙命令
    /// </summary>
    public class FirewallCommand : ILinuxCommand
    {
        public string Port { get; set; }
        public FirewallCommandTypeEnum FirewallCommandType { get; set; }
        public string BuildCommand(SystemVersionTypeEnum systemVersionType)
        {
            switch (FirewallCommandType)
            {
                case FirewallCommandTypeEnum.Allow:
                    switch (systemVersionType)
                    {
                        case SystemVersionTypeEnum.Ubuntu:
                            return $"sudo ufw allow {Port}/tcp";
                        case SystemVersionTypeEnum.CentOS:
                            return $"sudo firewall-cmd --zone=public --add-port={Port}/tcp --permanent";
                    }
                    break;
                case FirewallCommandTypeEnum.Reload:
                    switch (systemVersionType)
                    {
                        case SystemVersionTypeEnum.Ubuntu:
                            return $"echo true";
                        case SystemVersionTypeEnum.CentOS:
                            return $"sudo firewall-cmd --reload";
                    }
                    break;
                default:
                    break;
            }
            return string.Empty;
        }
    }
}
